<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('房屋信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                选择所属楼：<select id="fId" onchange="floorChange()"  name="fId">
                                <option value="">所有</option>
                                <option th:each="floor : ${floorSelect}" th:text="${floor.name}" th:value="${floor.floorId}"></option>
                            </select>
                            </li>
                            <li>
                                选择所属单元：<select id="uid"  name="unitId">

                            </select>
                            </li>
                            <li>
                                <p>房屋编号：</p>
                                <input type="text" name="roomNum"/>
                            </li>
                            <li>
                                <p>层数：</p>
                                <input type="text" name="layer"/>
                            </li>
                            <li>
                                <p>户型：</p>
                                <input type="text" name="apartment"/>
                            </li>
                            <li>
                                <p>建筑面积：</p>
                                <input type="text" name="builtUpArea"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:room:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:room:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:room:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:room:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:room:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:room:remove')}]];
        var datas = [[${@dict.getType('fz_room_status')}]];
        var prefix = ctx + "system/room";
        function floorChange(){
            var fid=$("#fId").val();
            $.ajax({url:"/system/room/untilSelect",type:"get",data:"floorId="+fid,async:true,success:function (reslut) {
                if (reslut!="") {
                    $("#uid").text("");
                    console.log(reslut);
                    $("#uid").append("<option selected='selected' value=''>请选择</option>");
                    $.each($.parseJSON(reslut), function (index, item) {

                            $("#uid").append("<option  value='" + item.unitId + "'>" + item.unitNum + "</option>");

                    });
                }else{
                    $("#uid").text("");
                }

                },error:function (reslut) {
                        layer.msg("操作失败", {icon: 2});
                    }
                });
        }
        $(function() {


            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "房屋信息",
                columns: [{
                    checkbox: true
                },
                    {
                        field : 'roomId',
                        title : '房屋ID',
                    },
                {
                    field : 'fId',
                    title : '楼栋ID',
                },
                {
                    field : 'unitId',
                    title : '单元ID'
                },
                {
                    field : 'roomNum', 
                    title : '房屋编号'
                },
                {
                    field : 'layer', 
                    title : '层数'
                },
                {
                    field : 'apartment', 
                    title : '户型'
                },
                {
                    field : 'builtUpArea', 
                    title : '建筑面积'
                },

                {
                    field : 'state', 
                    title : '房屋状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.roomId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.roomId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>